package com.txunda.zhuohired.aty.user.my;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ants.theantsgo.util.JSONUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.http.pst.InfoPst;

import java.util.Map;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/8 13:35
 * 功能描述：我的钱包
 * 联系方式：jiahuanchen@126.com
 */

public class MyPriceAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * 余额
     */
    @ViewInject(R.id.tv_my_price)
    private TextView tv_my_price;

    private InfoPst infoPst;
    private String token = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("我的钱包");
    }

    @Override
    @OnClick({R.id.tv_my_price_detail, R.id.tv_my_price_bank, R.id.tv_my_price_deposit})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_my_price_detail://账户明细
                startActivity(PriceDetailAty.class, null);
                break;
            case R.id.tv_my_price_bank://银行卡
                Bundle bundle = new Bundle();
                bundle.putString("bank_type", "1");
                startActivity(MyBankAty.class, bundle);
                break;
            case R.id.tv_my_price_deposit://提现
                startActivity(DepositAty.class, null);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_my_price;
    }

    @Override
    protected void initialized() {
        infoPst = new InfoPst(this);
        token = application.getUserInfo().get("data");
    }

    @Override
    protected void requestData() {
        initHttp();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        initHttp();
    }

    private void initHttp() {
        infoPst.wallet(token);
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("wallet")) {
            //            L.e("==========wallet==========", jsonStr);
            Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
            tv_my_price.setText(map.get("data"));
            return;
        }
    }
}
